package com.yunform.framework.hibernate;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

public class QueryClause {
	
	protected List<Criterion> andCriteria = new ArrayList<Criterion>();
	protected List<Order> orders = new ArrayList<Order>();
	
	public QueryClause andEqual(String propertyName, Object value){
		Criterion criterion = Restrictions.eq(propertyName, value);
		andCriteria.add(criterion);
		return this;
	}
	
	public QueryClause andNotEqual(String propertyName, Object value){
		Criterion criterion = Restrictions.ne(propertyName, value);
		andCriteria.add(criterion);
		return this;
	}

	public QueryClause andIn(String propertyName, Collection<?> values) {
		Criterion criterion = Restrictions.in(propertyName, values);
		andCriteria.add(criterion);
		return this;
	}
	
	public QueryClause andNotIn(String propertyName, Collection<?> values) {
		Criterion criterion = Restrictions.in(propertyName, values);
		andCriteria.add(criterion);
		return this;
	}
	public List<Criterion> getAndCriteria() {
		return andCriteria;
	}
	public QueryClause andGreate(String propertyName, Object value){
		Criterion criterion = Restrictions.gt(propertyName, value);
		andCriteria.add(criterion);
		return this;
	}
	public QueryClause andGreateEqual(String propertyName, Object value){
		Criterion criterion = Restrictions.ge(propertyName, value);
		andCriteria.add(criterion);
		return this;
	}
	
	public QueryClause addOrder(Order order){
		orders.add(order);
		return this;
	}

	public List<Order> getOrders() {
		return orders;
	}
}
